import numpy as np
import matplotlib.pyplot as plt

# 定义两个复数
z1 = 2 * (np.cos(np.pi/4) + 1j * np.sin(np.pi/4))
z2 = 1 * (np.cos(np.pi/6) + 1j * np.sin(np.pi/6))

# 计算复数乘积
z_product = z1 * z2

# 获取实部和虚部
x1, y1 = z1.real, z1.imag
x2, y2 = z2.real, z2.imag
x_product, y_product = z_product.real, z_product.imag

# 绘制矢量
plt.figure(figsize=(8, 8))
plt.axhline(0, color='black', linewidth=0.5)
plt.axvline(0, color='black', linewidth=0.5)

# 绘制 z1
plt.arrow(0, 0, x1, y1, head_width=0.1, head_length=0.1, fc='r', ec='r', label='$z_1$')
# 绘制 z2
plt.arrow(0, 0, x2, y2, head_width=0.1, head_length=0.1, fc='g', ec='g', label='$z_2$')
# 绘制 z1*z2
plt.arrow(0, 0, x_product, y_product, head_width=0.1, head_length=0.1, fc='b', ec='b', label='$z_1z_2$')

# 设置坐标轴范围
plt.xlim(-3, 3)
plt.ylim(-3, 3)
plt.grid(True)
plt.legend()
plt.title('Complex Number Multiplication in the Complex Plane')
plt.xlabel('Real Axis')
plt.ylabel('Imaginary Axis')
plt.show()